package com.alipay.app.groupmeal.standard.ui.c.pre;

import android.os.Build;
import android.view.Display;

import android.view.WindowManager;

import android.widget.LinearLayout;
import android.widget.TextView;


import androidx.constraintlayout.widget.ConstraintLayout;

import com.alipay.app.groupmeal.standard.R;
import com.alipay.app.groupmeal.standard.base.BasePresentation;

import com.alipay.app.groupmeal.standard.http.bean.resp.HexiaoOrderModel;
import com.alipay.app.groupmeal.standard.http.bean.resp.Result;
import com.alipay.app.groupmeal.standard.ui.c.abcp.CHexiaoAuthActivity;
import com.alipay.app.groupmeal.standard.ui.b.util.WIth;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.internal.observers.BlockingBaseObserver;


public class CHexiaoCardMainPre extends BasePresentation {

    private CHexiaoAuthActivity mActivity;

    private BackListener backListener;

    private TextView tv_close_time;

    private TextView tvLoading_b;

    private LinearLayout ll_cancel;

    private ConstraintLayout loadingCon;

    private LinearLayout payResLinear;

    private TextView payResMsgTv;

    private TextView amountPrice;

    private TextView accountPrice;

    private TextView youhuiPrice;

    public void setBackListener(BackListener backListener) {
        this.backListener = backListener;
    }


    public CHexiaoCardMainPre(CHexiaoAuthActivity outerContext, Display display) {
        super(outerContext, display);
        mActivity = outerContext;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_loading;
    }

    @Override
    protected void initView() {
        tv_close_time = findViewById(R.id.tv_close_time);
        tvLoading_b = findViewById(R.id.tvLoading_b);
        ll_cancel = findViewById(R.id.ll_cancel);
        loadingCon = findViewById(R.id.loadingCon);
        payResLinear = findViewById(R.id.payResLinear);
        payResMsgTv = findViewById(R.id.payResMsgTv);
        amountPrice = findViewById(R.id.amountPrice);
        accountPrice = findViewById(R.id.accountPrice);
        youhuiPrice = findViewById(R.id.youhuiPrice);
    }

    @Override
    protected void initData() {

    }


    public void cardHexiao(String cardsn) {

        new WIth(mActivity).cardHexiao(cardsn, new BlockingBaseObserver<Result<HexiaoOrderModel>>() {
            @Override
            public void onNext(@NonNull Result<HexiaoOrderModel> stringResult) {
                mActivity.runOnUiThread(() -> {
                    if (backListener != null) {
                        backListener.ResultListener(stringResult.getResult());
                    }
                });
            }

            @Override
            public void onError(@NonNull Throwable e) {
                mActivity.runOnUiThread(() -> {
                    if (backListener != null) {
                        backListener.ResultListener(null);
                    }
                });
            }
        });
        this.show();
    }

    public static interface BackListener {
        void ResultListener(HexiaoOrderModel hexiaoOrderModel);
    }

    public TextView getTv_close_time() {
        return tv_close_time;
    }

    public TextView getTvLoading_b() {
        return tvLoading_b;
    }

    public LinearLayout getLl_cancel() {
        return ll_cancel;
    }

    public ConstraintLayout getLoadingCon() {
        return loadingCon;
    }

    public LinearLayout getPayResLinear() {
        return payResLinear;
    }

    public TextView getPayResMsgTv() {
        return payResMsgTv;
    }

    public TextView getAmountPrice() {
        return amountPrice;
    }

    public TextView getAccountPrice() {
        return accountPrice;
    }

    public TextView getYouhuiPrice() {
        return youhuiPrice;
    }
}